package ft.ess.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Random;

public class U
{

	private static Random _random = null;
	
	private static Random getRandom()
	{
		if(_random==null)
		{
			_random = new Random();
		}
		return _random;
	}
	
	/**
	 * 取得 n 位随机数字
	 * @param n
	 * @return
	 */
	public static String getRandomNum(int n)
	{
		String ret = "";
		if(n>0 && n<=32)
		{
			Random rd = getRandom();
			StringBuffer sb = new StringBuffer(1+n);
			for(int i=0;i<n;i++)
			{
				sb.append(rd.nextInt(10));
			}
			ret = sb.toString();
		}
		return ret;
	}
	
	/**
	 * 取当前日期-时间<br />
	 * 格式：yyyyMMdd_HHmmss
	 * @return
	 */
	public static String getCurrentDate()
	{
		Date dt = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.US);
		return sdf.format(dt);
	}


}
